<template>
  <div>
    <div class="option">
      <el-button @click="info.isShow = true" type="primary" round plain
        >新增</el-button
      >
    </div>
    <el-table :data="seckillList">
      <el-table-column prop="id" label="ID" min-width="80"></el-table-column>
      <el-table-column
        prop="title"
        label="活动名称"
        min-width="180"
      ></el-table-column>
      <el-table-column prop="begintime" label="开始时间" min-width="180">
        <template v-slot="props">
          {{ props.row.begintime | dateFmt }}
        </template>
      </el-table-column>
      <el-table-column prop="endtime" label="结束时间" min-width="180">
        <template v-slot="props">
          {{ props.row.endtime | dateFmt("/") }}
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="180">
        <template v-slot="props">
            <el-button @click="edit(props.row)" type="primary" size="mini" round plain>编辑</el-button>
            <el-button @click="del(props.row.id)" type="danger" size="mini" round plain>删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 调用对话框组件 -->
    <Dialog :info="info" ref="dialog"/>
  </div>
</template>

<script>
// 导入对话框组件
import Dialog from "./Dialog";
// 导入vuex辅助函数
import { mapState, mapActions } from "vuex";
export default {
  data() {
    return {
      info: { isShow: false },
    };
  },
  components: { Dialog },
  computed: {
    ...mapState("seckill", ["seckillList"]),
  },
  methods: {
    ...mapActions("seckill", ["getSeckillListAction"]),
    // 编辑按钮点击事件处理函数
    edit(row){
      // 1-显示对话框组件
      this.info.isShow=true;
      // 2-将待编辑的活动对象传递给对话框组件
      this.$refs.dialog.setFormData(row);
    },
    // 删除
    del(id){
      this.$myConfirm(()=>{
        this.$axios.post('/seckdelete',{id}).then(res=>{
          if(res.code===200){
            this.$message.success(res.msg);
            // 更新活动列表
            this.getSeckillListAction();
          }else{
            this.$message.error(res.msg);
          }
        });
      });
    }
  },
  created() {
    // 请求活动列表
    this.getSeckillListAction();
  },
};
</script>

<style>
</style>